<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$user_name = "root";
$password = "haddons";
$database = "PPI";
$server = "127.0.0.1";

print "<h1>Import data</h1><p>";

$db_handle = mysql_connect($server, $user_name, $password);
print "Connection to the Server " . $db_handle . " opened <BR>";

$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {
    print "<B>connected to PPI DB - importing Lender data</B><p>";
    $sql = "LOAD DATA INFILE '/Library/WebServer/Documents/CashYourPPI/Lenders.csv'
        IGNORE
    INTO TABLE `PPI`.`lenders`
    FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\n'
    IGNORE 1 LINES (
    `CreateBy`, 
    `LenderName`, 
    `Address1`, 
    `Address2`, 
    `Address3`, 
    `City`,  
    `Postcode`, 
    `TelNo`, 
    `FaxNo`, 
    `Email`,
    `FSCS`,
    `FOSQ`);";
    print $sql . "<br>";
    //$result=mysql_query($sql);
    //print "RESULT= " . $result. "<br>";

    if (mysql_query($sql)) {
        print "lender data loaded OK<br>";
    } else {
        print "lender data won't load!<BR>";
    }
    
    mysql_close($db_handle);
}
?>
